import { put, takeLatest } from 'redux-saga/effects';
import { COUNTER_INCREASE_ASYNC, COUNTER_INCREASE } from './actions';

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))

function * asyncIncrease() {
  yield delay(1000);
  yield put({ type: COUNTER_INCREASE });
}

export function * countSaga() {
  // yield takeEvery(COUNTER_INCREASE_ASYNC, asyncIncrease);
  yield takeLatest(COUNTER_INCREASE_ASYNC, asyncIncrease);
}

export default countSaga;
